#ifndef FILELIST_H__
#define FILELIST_H__

#include "fingerprint.h"
#include <libxml/tree.h>
#include <QtCore>
#include <string>
#include <vector>

class FileList {
public:
	struct File {
        File() {
        }

        File(const QByteArray& name,
             const FingerPrint& fingerprint,
             quint32 size);

        const QByteArray& name() const {
            return name_;
        }
        const FingerPrint& fingerprint() const {
            return fingerprint_;
        }

		void set_name(const QByteArray &name) {
			name_ = name;
        }

		void set_fingerprint(const FingerPrint &finger) {
			fingerprint_ = finger;
        }

		
		void set_fingers(const std::vector<FingerPrint> &fingers) {
			fingers_ = fingers;
        }
		
		const std::vector<FingerPrint>& fingers(){
			return fingers_;
		}
		
        quint32 size() const {
            return size_;
        }

		void set_size(quint32 size) {
			size_ = size;
		}

        File* clone() const;

        void append(QByteArray* array) const;
        void parse(const QByteArray* array, int* position);

	private:
		QByteArray name_;
		FingerPrint fingerprint_;
		std::vector<FingerPrint> fingers_;
        quint32 size_;
	};

    FileList() {
    }

	~FileList();

    // citeste lista de fisiere dintr-un document xml
    // formatul fisierului xml este:
    // <fileslist>
    //  <file>
    //   <name>iepuras.txt</name>
    //   <size>100</size>
    //   <hash>0</hash>
	//   <hash>0</hash>
	//        ...
	//   <hash>0</hash>
    //  </file>
    // </filelist>
    //
    void read_from_xml(const std::string &filepath);

    // scrie lista de fisiere intr-un document xml
    // functia aloca memorie pentru document
    void write_to_xml(const std::string &filepath);

    File* at(int i) const {
        return list_.at(i);
    }

    int size() const {
        return list_.size();
    }

    // FileList devine stapanul fiecarui obiect inserat
    void push_back(File* file) {
        list_.push_back(file);
    }

private:
    std::vector<File*> list_;
};

#endif
